package com.cat.slidingWindow;

import java.util.Arrays;

/**
 * @author cat
 * @description https://leetcode.cn/problems/maximum-beauty-of-an-array-after-applying-operation/
 * @create 2025/7/29 16:35
 * @since JDK17
 */

public class Solution11 {
    public int maximumBeauty(int[] nums, int k) {
        // 排序
        Arrays.sort(nums);
        int ans = 0, n = nums.length, s, e;
        for (int l = 0, r = 0; r < n; l++) {
            s = nums[l] - k;
            e = nums[l] + k;
            while (r < n && nums[r] - k <= nums[l] + k) {
                r++;
            }
            ans = Math.max(ans, r - l);
        }
        return ans;
    }
}